package com.campus.campus.controller;

import com.campus.campus.job.dto.RepairRequestDTO;

import com.campus.campus.job.entity.RepairRequest;
import com.campus.campus.service.IRepairRequestService;
import com.campus.common.result.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/campusRepair")
@Tag(name = "校园报修服务")
public class RepairRequestController {

    @Autowired
    private IRepairRequestService repairRequestService;


    @ApiOperation(value = "报修详情")
    @GetMapping()
    public Result<RepairRequest> repairDetail(@RequestParam("id") Integer id) {
        return Result.success(repairRequestService.getById(id));
    }

    @ApiOperation(value = "我的报修列表")
    @GetMapping("/myRepair")
    public Result<List<RepairRequest>> myRepairDetail() {
        List<RepairRequest> list = repairRequestService.myRepairDetail();
        return Result.success(list);
    }

    @ApiOperation(value = "取消报修")
    @GetMapping("/cancel/{id}")
    public Result<Void> cancelRepair(@PathVariable Integer id) {
        repairRequestService.cancelRepair(id);
        return Result.success();
    }

    @ApiOperation(value = "报修申请.")
    @PostMapping("/repair")
    public Result<Void> repairRequest(@RequestBody RepairRequestDTO repairRequestDTO) {
        System.out.println("repairRequestDTO"+repairRequestDTO.toString());
        repairRequestService.repairRequest(repairRequestDTO);
        return Result.success();
    }

    @ApiOperation(value = "报修完成")
    @GetMapping("/accept/{id}")
    public Result<Void> acceptRepair(@PathVariable Integer id) {
        repairRequestService.acceptRepair(id);
        return Result.success();
    }

    @ApiOperation(value = " 报修列表")
    @GetMapping("/list")
    public Result<List<RepairRequest>> repairDetailList() {
        List<RepairRequest> list = repairRequestService.list();
        return Result.success(list);
    }


}
